﻿using System;
using System.Xml.Serialization;
using System.IO;


namespace QAHelper.Common
{
    public static class XMLHelper
    {
        #region Deserialize Given XML
        public static object GetDeserializeObject(string filePath, Type objType)
        {
            if (File.Exists(filePath))
            {
                try
                {
                    XmlSerializer serializer = new XmlSerializer(objType);
                    using (StreamReader reader = new StreamReader(filePath))
                    {
                        object obj = serializer.Deserialize(reader);
                        reader.Close();
                        reader.Dispose();

                        return obj;
                    }
                }

                catch (Exception ex)
                {
                }
            }
            else
            {
            }

            return null;
        }
        #endregion

        #region Serialize XML

        public static void Serialize(string file_name, object data)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(TestCaseStructure));
            TextWriter writer = new StreamWriter(file_name,true);
            serializer.Serialize(writer, data);
        }

        #endregion

    }
}
